﻿namespace Xioa_UI.Domain;

public static class AutomationCarryOut
{
    public static TResult? Run<T, TResult>(T key, T value)
    {
        var res = GetRunValue.GetRunningKeyValuePair<T, TResult>(key);
        if (string.IsNullOrWhiteSpace(res?.Key))
            throw new Exception("Not Found Running Method !");
        return CarryOut.Run<T, TResult>(res?.Key, res?.Value, value);
    }

    public static TResult? Run<T, TResult>(T key)
    {
        var res = GetRunValue.GetRunningKeyValuePair<T, TResult>(key);
        if (string.IsNullOrWhiteSpace(res?.Key))
            throw new Exception("Not Found Running Method !");
        return CarryOut.Run<T, TResult>(res?.Key, res?.Value);
    }

    public static void Run<T>(T key)
    {
        var res = GetRunValue.GetRunningKeyValuePair<T>(key);
        if (string.IsNullOrWhiteSpace(res?.Key))
            throw new Exception("Not Found Running Method !");
        CarryOut.Run<T>(res?.Key, res?.Value);
    }

    public static void Run<T>(T key, T value)
    {
        var res = GetRunValue.GetRunningKeyValuePair<T>(key);
        if (string.IsNullOrWhiteSpace(res?.Key))
            throw new Exception("Not Found Running Method !");
        CarryOut.Run<T>(res?.Key, res?.Value, value);
    }
}